/*
 * Field.scala
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.squela

trait Field[T] {

    type ResourceType <: Resource

    def name: String
    def length: Int
    def unique: Boolean
    def optional: Boolean
    def fieldType: Class[T]
    def resource: ResourceType

    def >(value: T) = {new >(this, value)}
    def >=(value: T) = {new >=(this, value)}
    def <(value: T) = {new <(this, value)}
    def <=(value: T) = {new <=(this, value)}
    def ->(value: T) = {new ->(this, value)}
    def <>(value: T) = {new <>(this, value)}
    def like(like: String) = if(fieldType == classOf[String]){
        Like(this.asInstanceOf[Field[String]], like)
    } else {
        throw new IllegalStateException("Field is not of type String")
    }
    def in(query: Query) = In(this, query)

    override def toString = name
}
